package net.sk.china.city.service.impl;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import net.sk.china.common.exception.ServiceException;
import net.sk.china.city.utils.PlatformIdHolder;
import net.sk.china.city.service.IArHomeShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import net.sk.china.city.mapper.ArHomeShopMapper;
import net.sk.china.city.domain.ArHomeShop;

/**
 * 店铺管理Service业务层处理
 * 
 * @author gxf
 * @date 2024-05-08
 */
@Service
public class ArHomeShopServiceImpl implements IArHomeShopService
{
    @Autowired
    private ArHomeShopMapper arHomeShopMapper;

    /**
     * 查询店铺管理
     * 
     * @param id 店铺管理主键
     * @return 店铺管理
     */
    @Override
    public ArHomeShop selectArHomeShopById(Long id)
    {
        return arHomeShopMapper.selectArHomeShopById(id);
    }

    /**
     * 查询店铺管理列表
     * 
     * @param arHomeShop 店铺管理
     * @return 店铺管理
     */
    @Override
    public List<ArHomeShop> selectArHomeShopList(ArHomeShop arHomeShop)
    {
        return arHomeShopMapper.selectArHomeShopList(arHomeShop);
    }

    /**
     * 新增店铺管理
     * 
     * @param arHomeShop 店铺管理
     * @return 结果
     */
    @Override
    public int insertArHomeShop(ArHomeShop arHomeShop)
    {
        arHomeShop.setPlatformId(PlatformIdHolder.getPlatformId());
        return arHomeShopMapper.insertArHomeShop(arHomeShop);
    }

    /**
     * 修改店铺管理
     * 
     * @param arHomeShop 店铺管理
     * @return 结果
     */
    @Override
    public int updateArHomeShop(ArHomeShop arHomeShop)
    {
        return arHomeShopMapper.updateArHomeShop(arHomeShop);
    }

    /**
     * 批量删除店铺管理
     * 
     * @param ids 需要删除的店铺管理主键
     * @return 结果
     */
    @Override
    public int deleteArHomeShopByIds(Long[] ids)
    {
//        return arHomeShopMapper.deleteArHomeShopByIds(ids);
        for (Long id : ids){
            ArHomeShop arHomeShop = new ArHomeShop();
            arHomeShop.setId(id);
            arHomeShop.setDelFlag("2");
            int i = arHomeShopMapper.updateArHomeShop(arHomeShop);
            if(i <=0 ){
                throw new ServiceException("删除失败",409);
            }
        }
        return 1;
    }

    /**
     * 删除店铺管理信息
     * 
     * @param id 店铺管理主键
     * @return 结果
     */
    @Override
    public int deleteArHomeShopById(Long id)
    {
        ArHomeShop arHomeShop = new ArHomeShop();
        arHomeShop.setId(id);
        arHomeShop.setDelFlag("2");
        int i = arHomeShopMapper.updateArHomeShop(arHomeShop);
        if(i <=0 ){
            throw new ServiceException("删除失败",409);
        }
        return 1;
    }

    @Override
    public List<ArHomeShop> getShops(){
        return arHomeShopMapper.selectList(new QueryWrapper<ArHomeShop>()
                .eq("del_flag","0")
                .like("platform_id","%"+ PlatformIdHolder.getPlatformId() +"%"));
    }
}
